package com.example.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.blog.entity.DictionaryItem;
import com.example.blog.entity.dto.dictionaryGroup.AddOrUpdateDictGroupDTO;
import com.example.blog.mapper.DictionaryItemMapper;
import com.example.blog.service.DictionaryItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.blog.util.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 字典项表 服务实现类
 * </p>
 *
 * @author wlh
 * @since 2024-01-10
 */
@Service
public class DictionaryItemServiceImpl extends ServiceImpl<DictionaryItemMapper, DictionaryItem> implements DictionaryItemService {

    @Override
    public void addOrUpdate(AddOrUpdateDictGroupDTO addOrUpdateDictGroupDTO) {
        DictionaryItem dictionaryItem = BeanUtils.copyProperties(addOrUpdateDictGroupDTO, DictionaryItem.class);
        saveOrUpdate(dictionaryItem);
    }

    @Override
    public List<DictionaryItem> getByGroupId(Long groupId) {
        LambdaQueryWrapper<DictionaryItem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DictionaryItem::getGroupId, groupId);
        return list(queryWrapper);
    }
}
